package com.zoffy.oj_backend.judge.codesandbox.impl.ExampleCodeSandbox.codeExcuter;

import com.zoffy.oj_backend.judge.codesandbox.model.ExecuteMessage;

import java.io.File;
import java.util.List;

public class JavaCodeExecutor extends AbstractCodeExecutor{
    private static final String GLOBAL_JAVA_CLASS_NAME = "Main.java";
    private static final String JAVA_COMPILE_COMMAND="javac -encoding utf8 ";
    private static final String JAVA_RUNNING_COMMAND="java -Xmx256m -Dfile.encoding=UTF-8 -cp %s Main %s";
    @Override
    public File saveCode2File(String code) {
        return saveCode2File(code,GLOBAL_JAVA_CLASS_NAME);
    }

    @Override
    public ExecuteMessage compileCode(File codeFile) {
        return compileCode(codeFile,JAVA_COMPILE_COMMAND);
    }

    @Override
    public List<ExecuteMessage> runCodeFile(File file, List<String> inputList) {
        return runCodeFile(file,inputList,JAVA_RUNNING_COMMAND);
    }
}
